<?php

/**
 * 
 * @desc session操作类
 * 
 * @author keluo <pycorvn@yeah.net>
 * @since 2012-2-21 11:45:05
 * @link http://www.scabish.cn/framework
 * 
 */

class SCSession {
	
	/**
	 * 
	 * session标识
	 * @var string
	 */
	private $sessionId;
	
	private $data;
	
	function __construct() {
		if(!isset($_SESSION)) {
			session_start();
		}
		$data = new stdClass();
		$this->sessionId = session_id();
	}
	
	function set($key, $value) {
		$this->data->$key = $value;
		$_SESSION[$this->sessionId] = serialize($this->data);
	}

	function get($key) {
		return isset($this->data->$key) ? $this->data->$key : false;
	}
	
	function delete($key) {
		if(isset($this->data->key)) {
			unset($this->data->key);
			$_SESSION[$this->sessionId] = serialize($this->data);
		}
	}
	
	function clear() {
		$this->data->$key = new stdClass();
		session_unset();
	}	
}